/*
* Portuguese eID Card API .NET Wrapper
*
* Written by Fernando Nunes (fernando.nunes@devscope.net)
* Copyright (c) 2009 DevScope Information Systems
*
* This library is free software; you can redistribute it and/or 
* modify it under the terms of the GNU Lesser General Public 
* License as published by the Free Software Foundation; either 
* version 2.1 of the License, or (at your option) any later version. 
* 
* This library is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
* Lesser General Public License for more details. 
* 
* You should have received a copy of the GNU Lesser General Public 
* License along with this library; if not, write to the Free Software 
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 
*/

#pragma once
#include "Stdafx.h"
#include "Address.h"
#include "Interop.h"

using namespace System;
using namespace DevScope::CartaoDeCidadao;

Address::Address()
{
}

Address::Address(const PTEID_ADDR& i)
{
	this->Version = i.version;
	this->AddressType = Interop::CStrToNetStr((char*)i.addrType);
	this->Country = Interop::CStrToNetStr((char*)i.country);
	this->District = Interop::CStrToNetStr((char*)i.district);
	this->DistrictDescription = Interop::CStrToNetStr((char*)i.districtDesc);
	this->Municipality = Interop::CStrToNetStr((char*)i.municipality);
	this->MunicipalityDescription = Interop::CStrToNetStr((char*)i.municipalityDesc);
	this->Freguesia = Interop::CStrToNetStr((char*)i.freguesia);
	this->FreguesiaDescription = Interop::CStrToNetStr((char*)i.freguesiaDesc);
	this->StreetTypeAbbreviation = Interop::CStrToNetStr((char*)i.streettypeAbbr);
	this->StreetType = Interop::CStrToNetStr((char*)i.streettype);
	this->Street = Interop::CStrToNetStr((char*)i.street);
	this->BuildingAbbreviation = Interop::CStrToNetStr((char*)i.buildingAbbr);
	this->Building = Interop::CStrToNetStr((char*)i.building);
	this->Door = Interop::CStrToNetStr((char*)i.door);
	this->Floor = Interop::CStrToNetStr((char*)i.floor);
	this->Side = Interop::CStrToNetStr((char*)i.side);
	this->Place = Interop::CStrToNetStr((char*)i.place);
	this->Locality = Interop::CStrToNetStr((char*)i.locality);
	this->CP4 = Interop::CStrToNetStr((char*)i.cp4);
	this->CP3 = Interop::CStrToNetStr((char*)i.cp3);
	this->Postal = Interop::CStrToNetStr((char*)i.postal);
	this->NumMorada = Interop::CStrToNetStr((char*)i.numMor);
	this->CountryDescriptionF = Interop::CStrToNetStr((char*)i.countryDescF);
	this->AddressF = Interop::CStrToNetStr((char*)i.addressF);
	this->RegionF = Interop::CStrToNetStr((char*)i.regioF);
	this->LocalityF = Interop::CStrToNetStr((char*)i.localityF);
	this->PostalF = Interop::CStrToNetStr((char*)i.postalF);
	this->NumMoradaF = Interop::CStrToNetStr((char*)i.numMorF);
}

PTEID_ADDR Address::ToUnmanaged()
{
	PTEID_ADDR personAddress = PTEID_ADDR();
	personAddress.version = this->Version;
	Interop::copyNetToStr(this->AddressType, personAddress.addrType);
	Interop::copyNetToStr(this->Country, personAddress.country);
	Interop::copyNetToStr(this->District, personAddress.district);
	Interop::copyNetToStr(this->DistrictDescription, personAddress.districtDesc);
	Interop::copyNetToStr(this->Municipality, personAddress.municipality);
	Interop::copyNetToStr(this->MunicipalityDescription, personAddress.municipalityDesc);
	Interop::copyNetToStr(this->Freguesia, personAddress.freguesia);
	Interop::copyNetToStr(this->FreguesiaDescription, personAddress.freguesiaDesc);
	Interop::copyNetToStr(this->StreetTypeAbbreviation, personAddress.streettypeAbbr);
	Interop::copyNetToStr(this->StreetType, personAddress.streettype);
	Interop::copyNetToStr(this->Street, personAddress.street);
	Interop::copyNetToStr(this->BuildingAbbreviation, personAddress.buildingAbbr);
	Interop::copyNetToStr(this->Building, personAddress.building);
	Interop::copyNetToStr(this->Door, personAddress.door);
	Interop::copyNetToStr(this->Floor, personAddress.floor);
	Interop::copyNetToStr(this->Side, personAddress.side);
	Interop::copyNetToStr(this->Place, personAddress.place);
	Interop::copyNetToStr(this->Locality, personAddress.locality);
	Interop::copyNetToStr(this->CP4, personAddress.cp4);
	Interop::copyNetToStr(this->CP3, personAddress.cp3);
	Interop::copyNetToStr(this->Postal, personAddress.postal);
	Interop::copyNetToStr(this->NumMorada, personAddress.numMor);
	Interop::copyNetToStr(this->CountryDescriptionF, personAddress.countryDescF);
	Interop::copyNetToStr(this->AddressF, personAddress.addressF);
	Interop::copyNetToStr(this->RegionF, personAddress.regioF);
	Interop::copyNetToStr(this->LocalityF, personAddress.localityF);
	Interop::copyNetToStr(this->PostalF, personAddress.postalF);
	Interop::copyNetToStr(this->NumMoradaF, personAddress.numMorF);
	return personAddress;
}